package org.chatboleh;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import org.chatboleh.util.CurrencyToWords;
import org.chatboleh.util.Language;
import org.chatboleh.util.PrintUtilities;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;

//VS4E -- DO NOT REMOVE THIS LINE!
public class MyFrame extends JFrame {

	private static final long serialVersionUID = 1L;
	private JFormattedTextField jFormattedTextField0;
	private JTextArea jTextArea0;
	private JScrollPane jScrollPane0;
	private JButton jButton0;
	private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
	public MyFrame() {
		initComponents();
	}

	private void initComponents() {
		setLayout(new GroupLayout());
		add(getJScrollPane0(), new Constraints(new Leading(86, 369, 10, 10), new Leading(33, 132, 10, 10)));
		add(getJFormattedTextField0(), new Constraints(new Leading(87, 366, 12, 12), new Leading(6, 10, 10)));
		add(getJButton0(), new Constraints(new Leading(202, 10, 10), new Leading(193, 10, 10)));
		addWindowStateListener(new WindowStateListener() {
			@Override
			public void windowStateChanged(WindowEvent event) {
				windowStateWindowStateChanged(event.getNewState());
			}
		});
		setSize(503, 289);
	}

	private JButton getJButton0() {
		if (jButton0 == null) {
			jButton0 = new JButton();
			jButton0.setText("jButton0");
			jButton0.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent event) {
					jButton0MouseMouseClicked(event);
				}
			});
		}
		return jButton0;
	}

	private JScrollPane getJScrollPane0() {
		if (jScrollPane0 == null) {
			jScrollPane0 = new JScrollPane();
			jScrollPane0.setViewportView(getJTextArea0());
		}
		return jScrollPane0;
	}

	private JTextArea getJTextArea0() {
		if (jTextArea0 == null) {
			jTextArea0 = new JTextArea();
			jTextArea0.setEditable(false);
			jTextArea0.setLineWrap(true);
			jTextArea0.setText("jTextArea0");
		}
		return jTextArea0;
	}

	private JFormattedTextField getJFormattedTextField0() {
		if (jFormattedTextField0 == null) {
			jFormattedTextField0 = new JFormattedTextField();
			jFormattedTextField0.setText("0.00");
			jFormattedTextField0.addPropertyChangeListener(new PropertyChangeListener() {
				@Override
				public void propertyChange(PropertyChangeEvent event) {
					jFormattedTextField0PropertyChangePropertyChange(event);
				}
			});
		}
		return jFormattedTextField0;
	}

	private static void installLnF() {
		try {
			String lnfClassname = PREFERRED_LOOK_AND_FEEL;
			if (lnfClassname == null)
				lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
			UIManager.setLookAndFeel(lnfClassname);
		} catch (Exception e) {
			System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
					+ " on this platform:" + e.getMessage());
		}
	}

	/**
	 * Main entry of the class.
	 * Note: This class is only created so that you can easily preview the result at runtime.
	 * It is not expected to be managed by the designer.
	 * You can modify it as you like.
	 */
	public static void main(String[] args) {
		installLnF();
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				MyFrame frame = new MyFrame();
				frame.setDefaultCloseOperation(MyFrame.EXIT_ON_CLOSE);
				frame.setTitle("MyFrame");
				frame.getContentPane().setPreferredSize(frame.getSize());
				frame.pack();
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
			}
		});
	}

	private void jFormattedTextField0PropertyChangePropertyChange(PropertyChangeEvent event) {
		String text;
		text = CurrencyToWords.convert(jFormattedTextField0.getText(), Language.ENGLISH);
		jTextArea0.setText(text);
	}

	private void jButton0MouseMouseClicked(MouseEvent event) {
		PrintUtilities.printComponent(this);
	}

	private void windowStateWindowStateChanged(int event) {
		if(event == WindowEvent.WINDOW_ACTIVATED){
			System.out.println("WINDOW_ACTIVATED");
		}
		if(event == WindowEvent.WINDOW_GAINED_FOCUS){
			System.out.println("WINDOW_GAINED_FOCUS");
		}
		if(event == WindowEvent.WINDOW_OPENED){
			System.out.println("WINDOW_OPENED");
		}
		if(event == WindowEvent.WINDOW_CLOSING){
			System.out.println("WINDOW_CLOSING");
		}
	}

}
